$.ajax({
  type: 'get',
  url: "/ws"
}).then((a) => {
  console.log(111111111, a);
  window.socketPath = "ws://" + a.IPv4Address + ":" + a.port;
  setTimeout(() => {
    startWsConnect()
  }, 2000)
});

function startWsConnect() {
  if (window.WebSocket) {
    window.ws = new WebSocket(window.socketPath);
    console.log('开始连接eiwebsocket')
    ws.onopen = function (e) {
      console.log("连接服务器成功");
      ws.send("game1");
    };
    ws.onclose = function (e) {
      console.log("服务器关闭");
    };
    ws.onerror = function () {
      console.log("连接出错");
    };

    ws.onmessage = function (e) {
      console.log("收到了消息", e.data);
      document.querySelector("#msg-content").innerHTML = e.data
    }
  }
}

function send(message = 'message-1') {
  ws.send(message);
}

window.setInterval(() => {
  send(Math.random())
}, 4000);
